<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/common.js"></script>
</head>
<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "releaseList" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>已发布游记管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/travel/releaseList.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>

                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text" name="keyword" value="${(qo.keyword)!}">
                    </div>
                    <button id="btn_query" class="btn btn-default">
                        <span class="glyphicon glyphicon-search"></span> 查询
                    </button>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>标题</th>
                        <th>封面</th>
                        <th>地点</th>
                        <th>作者</th>
                        <th>发布时间</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.title}</td>
                        <td><img src='${entity.coverUrl}' width="30px"/></td>
                        <td>${entity.place.name}</td>
                        <td>${entity.author.nickName}</td>
                        <td>${entity.releaseTime?string("yyyy-MM-dd HH:mm:ss")}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a href="javascript:void(0);" class="lookBtn" data-did="${entity.id}">查看游记</a>
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="changeStateBtn" data-did="${entity.id}">取消发布</a>
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="commendBtn"  data-json='${entity.json}'>推荐</a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>

              <#include "../common/page.ftl"/>
            </div>
        </div>
    </div>
</div>
<#--模态框-->
<div class="modal fade" id="travelContentModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框头部-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查看文章</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">
            </div>
        <#--模态框底部-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<div id="travelCommendModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="commendForm" class="form-horizontal" method="post" action="/travelCommend/saveOrUpdate.do" enctype="multipart/form-data" style="margin: -3px 118px">
                    <#--游记推荐表的id-->
                    <input id="travelCommendId" type="hidden" name="id" value="" />
                    <#--游记的id-->
                    <input id="travelId" type="hidden" name="travelId" value="" />
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title" placeholder="标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle" placeholder="副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="200px"/><#--用来显示的封面图片-->
                            <input type="hidden" name="coverUrl" /><#--用来提交表单的-->
                            <input type="file" class="form-control"  name="file" ><#--用来上传文件的控件-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐时间</label>
                        <div class="col-sm-6">
                            <input type="text" id="schedule" name="schedule" class="form-control" onclick="WdatePicker()">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐类型</label>
                        <div class="col-sm-6">
                            <select id="type" class="form-control" autocomplete="off" name="type" >
                                <option value="1">每月推荐</option>
                                <option value="2">每周推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        //将文章内容显示在模态框中
        $(".lookBtn").click(function () {
            //获取自定义属性的值
            var id=$(this).data("did");
            //发送异步请求去获取文章内容
            $.get("/travel/getContentById.do",{id:id},function (data) {
                console.log(data);
                //给模态框内容赋值
                $("#travelContentModal .modal-body").html(data.content);
            });
            $("#travelContentModal").modal("show");
        });
        //取消发布功能
        $(".changeStateBtn").click(function () {
            //获取自定义属性
            var id=$(this).data("did");
            var state=1;
            //发送异步请求去修改状态
            $.post("/travel/changeState.do",{id:id,state:state},function (data) {
                doSuccess();
            });
        })
        //推荐按钮
        $(".commendBtn").click(function () {
            //获取自定义的jaon属性
            var json=$(this).data("json");
            console.log(json);
            //回显三个,从travel的json中获取的
            $("#travelId").val(json.id);
            $("#title").val(json.title);
            $("#coverUrl").attr("src",json.coverUrl);
            //图片隐藏域
            $("#commendForm input[name='coverUrl']").val(json.coverUrl);
            $("#travelCommendModal").modal("show");
        });
        //推荐按钮提交
        $("#saveBtn").click(function () {
            $("#commendForm").ajaxSubmit(function (data) {
                doSuccess();
            });
        });
    });
</script>
<style>
    #travelContentModal img {
        width: 100%;
    }
    #travelContentModal .modal-body {
        max-height: 600px;
        overflow-y: scroll;
    }

</style>
</body>
</html>